local zhuilie = fk.CreateSkill {
  name = "tyj_heg__zhuilie",
}

Fk:loadTranslationTable {
  ["tyj_heg__zhuilie"] = "追猎",
  [":tyj_heg__zhuilie"] = "出牌阶段结束时，若你本阶段造成过伤害，你可以对自己造成1点伤害，然后将本回合的下一个阶段改为出牌阶段。",

  ["$tyj_heg__zhuilie1"] = "哈哈！我喜欢，猎夺沙场的快感。",
  ["$tyj_heg__zhuilie2"] = "追敌夺魂，猎尽贼寇。",
}
zhuilie:addEffect(fk.EventPhaseEnd, {
  anim_type = "offensive",
  events = { fk.EventPhaseEnd },
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(zhuilie.name) and target == player and target.phase == Player.Play then
      return #player.room.logic:getActualDamageEvents(1, function(e)
        return e.data.from == player
      end, Player.HistoryPhase) > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:damage {
      from = player,
      to = player,
      damage = 1,
      skillName = zhuilie.name,
    }
    if player:isAlive() then
      room:setPlayerMark(player, "tyj_heg__zhuilie-turn", 1)
    end
  end,
})
zhuilie:addEffect(fk.EventPhaseChanging, {
  late_refresh = true,
  can_refresh = function(self, event, target, player, data)
    if target == player and player:getMark("tyj_heg__zhuilie-turn") > 0 and data.phase > Player.RoundStart and data.phase < Player.NotActive then
      local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      if turn_event == nil then return false end
      return true
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "tyj_heg__zhuilie-turn", 0)
    room:sendLog {
      type = "#PhaseChanged",
      from = player.id,
      arg = Util.PhaseStrMapper(data.phase),
      arg2 = "phase_play",
    }
    data.phase = Player.Play
  end,
})

return zhuilie
